﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OracleClient;
using System.Collections.Generic;

/// <summary>
///TowerDAOs 的摘要说明
/// </summary>
public class TowerDAOs
{
    private static TowerDAOs instance = null;
	public TowerDAOs()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}
    public static TowerDAOs getInstance()
    {
        if (instance == null)
        {
            instance = new TowerDAOs();
        }
        return instance;
    }
    public List<String> getTowerNameList(String lname)
    {
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        cmd.CommandText = "Select distinct EQUIPMENT from pgms_tower_info where TRANSMISSIONLINE=:lineName and towersheet <> 'TOWER6'";
        cmd.Parameters.Add(":lineName", OracleType.VarChar);
        cmd.Parameters[":lineName"].Value = lname;
        conn.Open();
        OracleDataReader dr = cmd.ExecuteReader();
        List<String> nameList = new List<string>();
        if (dr.HasRows)
        {
            while (dr.Read())
            {
                if(!dr.IsDBNull(0))
                    nameList.Add(dr.GetString(0));
            }
        }
        dr.Close();
        conn.Close();
        return nameList;
    }
    
    /* 状态检测-检测表=L2实时数据查询
     * lname:线路名称
     * tname:塔杆名称
     */ 
    public Tower getTowerByName(String lname,String tname)
    {
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        cmd.CommandText = "Select VALUE from (select VALUE from PGMS_CURRENT_INFO t where t.TRANSMISSIONLINE = :lineName and EQUIPMENT=:towerName and t.NAME='工作温度' order by t.TIME desc) where rownum = 1";
        cmd.Parameters.Add(":lineName", OracleType.VarChar);
        cmd.Parameters[":lineName"].Value = lname;
        cmd.Parameters.Add(":towerName", OracleType.VarChar);
        cmd.Parameters[":towerName"].Value = tname;
        conn.Open();
        OracleDataReader dr = cmd.ExecuteReader();
        Tower tower = new Tower(tname);
        if (dr.HasRows)
        {
            dr.Read();
            if(!dr.IsDBNull(0))
                tower.Temperature = dr.GetFloat(0)+"";
        }
        cmd.CommandText = "Select VALUE from (select VALUE from PGMS_CURRENT_INFO t where t.TRANSMISSIONLINE = :lineName and EQUIPMENT=:towerName and t.NAME='电池电压' order by t.TIME desc) where rownum = 1";
        dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            dr.Read();
            if (!dr.IsDBNull(0))
                tower.BatteryVoltage = dr.GetFloat(0)+"";
        }
        cmd.CommandText = "Select VALUE from (select VALUE from PGMS_CURRENT_INFO t where t.TRANSMISSIONLINE = :lineName and EQUIPMENT=:towerName and t.NAME='在线状态' order by t.TIME desc) where rownum = 1";
        dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            dr.Read();
            if (!dr.IsDBNull(0))
                tower.OnlineStatus = dr.GetFloat(0)+"";
        }
        cmd.CommandText = "Select VALUE from (select VALUE from PGMS_CURRENT_INFO t where t.TRANSMISSIONLINE = :lineName and EQUIPMENT=:towerName and t.NAME='综合告警' order by t.TIME desc) where rownum = 1";
        dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            dr.Read();
            if (!dr.IsDBNull(0))
                tower.Alarm = (dr.GetFloat(0) > 0 ? true : false);
        }

        cmd.CommandText = "Select max(time) from PGMS_CURRENT_INFO where EQUIPMENT=:towerName and TRANSMISSIONLINE =:lineName and (NAME='工作温度')";
        dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            dr.Read();
            if (!dr.IsDBNull(0))
                tower.Time = dr.GetDateTime(0).ToString();
        }
        dr.Close();
        conn.Close();
        return tower;
    }

    
    /*
     * 数据查询-获得杆塔的类型
     * lname:线路名称
     * tname:杆塔名称
     */
    public String getTowerType(String lname,String tname)
    {
        String type="";
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        cmd.CommandText = "select towersheet from pgms_tower_info where transmissionline=:lineName and equipment=:towerName";
        cmd.Parameters.Add(":lineName", OracleType.VarChar);
        cmd.Parameters[":lineName"].Value = lname;
        cmd.Parameters.Add(":towerName", OracleType.VarChar);
        cmd.Parameters[":towerName"].Value = tname;
        conn.Open();
        OracleDataReader dr = cmd.ExecuteReader();
        if (dr.HasRows)
        {
            dr.Read();
            if (!dr.IsDBNull(0))
                type = dr.GetString(0);
        }
        conn.Close();
    return type;
    }
    public List<String> getTowerHistoryTableNameList(String lname,String tname,DateTime begin,DateTime end)
    {
        List<String> tableNameList = new List<string>();
        String towerType = getTowerType(lname, tname);
        DateTime p;
        for (p = begin; p <= end; p=p.AddYears(1))
        {
            tableNameList.Add("PGMS_" + towerType+"_" + p.Year.ToString("D4") );
        }
        if (p.Year == end.Year)//剩下一个月未处理
        {
            tableNameList.Add("PGMS_" + towerType+"_" + p.Year.ToString("D4") );
        }
        return tableNameList;
    }
    /* 
     * 数据查询-装置测量-历史数据查询 3.1
     * lname:线路名称
     * tname:杆塔名称
     * ename:设备分类名 {测温装置，自动气象站，覆冰装置，杆塔倾斜装置，杆塔防盗装置}
     * begin:开始时间
     * end:结束时间
    */
    public DataTable getDTDataQueryZZCL(String lname,String tname,String ename,DateTime begin,DateTime end)
    {
        DataTable metricHistoryDataTable = new DataTable();
        try
        {
            String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
            OracleConnection conn = new OracleConnection(connectionString);
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            conn.Open();
            List<String> tableNameList = getTowerHistoryTableNameList(lname, tname, begin, end);
            if (ename.Equals("测温装置"))
            {
                metricHistoryDataTable.Columns.Add("线路名称");
                metricHistoryDataTable.Columns.Add("杆塔名称");
                metricHistoryDataTable.Columns.Add("装置名称");
                metricHistoryDataTable.Columns.Add("采样时间");
                metricHistoryDataTable.Columns.Add("导线温度");
                metricHistoryDataTable.Columns.Add("导线温度_ABNORMAL");
                for (int i = 0; i < tableNameList.Count; i++)
                {
                    cmd.CommandText = @"Select TRANSMISSIONLINE,EQUIPMENT,FACILITY,TIME,TEMPERATUREOF_LINE,TEMPERATUREOF_LINE_ABNORMAL from " + tableNameList[i] + " where TRANSMISSIONLINE = :lineName and EQUIPMENT=:towerName and (TIME between :timeBegin and :timeEnd)";
                    cmd.Parameters.Add(":lineName", OracleType.VarChar);
                    cmd.Parameters[":lineName"].Value = lname;
                    cmd.Parameters.Add(":towerName", OracleType.VarChar);
                    cmd.Parameters[":towerName"].Value = tname;
                    cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                    cmd.Parameters[":timeBegin"].Value = begin;
                    cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                    cmd.Parameters[":timeEnd"].Value = end;
                    OracleDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5))
                                metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetString(2), dr.GetDateTime(3), dr.GetFloat(4), dr.GetInt64(5) });
                        }
                    }
                }
            }
            else if (ename.Equals("自动气象站"))
            {
                metricHistoryDataTable.Columns.Add("线路名称");
                metricHistoryDataTable.Columns.Add("杆塔名称");
                metricHistoryDataTable.Columns.Add("装置名称");
                metricHistoryDataTable.Columns.Add("采样时间");
                metricHistoryDataTable.Columns.Add("温度");//4
                metricHistoryDataTable.Columns.Add("温度_ABNORMAL");
                metricHistoryDataTable.Columns.Add("湿度");
                metricHistoryDataTable.Columns.Add("湿度_ABNORMAL");
                metricHistoryDataTable.Columns.Add("风速");
                metricHistoryDataTable.Columns.Add("风速_ABNORMAL");
                metricHistoryDataTable.Columns.Add("风向");
                metricHistoryDataTable.Columns.Add("风向_ABNORMAL");
                metricHistoryDataTable.Columns.Add("雨量");
                metricHistoryDataTable.Columns.Add("雨量_ABNORMAL");
                metricHistoryDataTable.Columns.Add("气压");
                metricHistoryDataTable.Columns.Add("气压_ABNORMAL");
                metricHistoryDataTable.Columns.Add("日照强度");
                metricHistoryDataTable.Columns.Add("日照强度_ABNORMAL");
                for (int i = 0; i < tableNameList.Count; i++)
                {
                    cmd.CommandText = @"Select TRANSMISSIONLINE,EQUIPMENT,FACILITY,TIME,
                                       TEMPERATURE,TEMPERATURE_ABNORMAL,HUMIDITY,HUMIDITY_ABNORMAL,WINDSPEED,WINDSPEED_ABNORMAL,
                                       WINDDIRECTION,WINDDIRECTION_ABNORMAL,ATOME_PRESSURE,ATOME_PRESSURE_ABNORMAL,RAINFALL,RAINFALL_ABNORMAL,
                                       SUNLIGHT,SUNLIGHT_ABNORMAL from "
                        + tableNameList[i] + " where TRANSMISSIONLINE = :lineName and EQUIPMENT=:towerName and (TIME between :timeBegin and :timeEnd)";

                    cmd.Parameters.Add(":lineName", OracleType.VarChar);
                    cmd.Parameters[":lineName"].Value = lname;
                    cmd.Parameters.Add(":towerName", OracleType.VarChar);
                    cmd.Parameters[":towerName"].Value = tname;
                    cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                    cmd.Parameters[":timeBegin"].Value = begin;
                    cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                    cmd.Parameters[":timeEnd"].Value = end;

                    OracleDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5) && !dr.IsDBNull(6) && !dr.IsDBNull(7) && !dr.IsDBNull(8) && !dr.IsDBNull(9) && !dr.IsDBNull(10) && !dr.IsDBNull(11) && !dr.IsDBNull(12) && !dr.IsDBNull(13) && !dr.IsDBNull(14) && !dr.IsDBNull(15) && !dr.IsDBNull(16) && !dr.IsDBNull(17))
                                metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetString(2), dr.GetDateTime(3), dr.GetFloat(4), dr.GetInt64(5), dr.GetFloat(6), dr.GetInt64(7), dr.GetFloat(8), dr.GetInt64(9), dr.GetFloat(10), dr.GetInt64(11), dr.GetFloat(12), dr.GetInt64(13), dr.GetFloat(14), dr.GetInt64(15), dr.GetFloat(16), dr.GetInt64(17) });
                        }
                    }
                }
            }
            else if (ename.Equals("覆冰装置"))
            {
                metricHistoryDataTable.Columns.Add("线路名称");
                metricHistoryDataTable.Columns.Add("杆塔名称");
                metricHistoryDataTable.Columns.Add("装置名称");
                metricHistoryDataTable.Columns.Add("采样时间");
                metricHistoryDataTable.Columns.Add("导线倾斜角");
                metricHistoryDataTable.Columns.Add("导线倾斜角_ABNORMAL");
                metricHistoryDataTable.Columns.Add("导线拉力");
                metricHistoryDataTable.Columns.Add("导线拉力_ABNORMAL");
                for (int i = 0; i < tableNameList.Count; i++)
                {
                    cmd.CommandText = @"Select TRANSMISSIONLINE, EQUIPMENT, FACILITY,TIME, ANGLEOF_LINE1,ANGLEOF_LINE1_ABNORMAL,FORCEOF_LINE,FORCEOF_LINE_ABNORMAL from " + tableNameList[i] +
                        " where TRANSMISSIONLINE = :lineName and EQUIPMENT=:towerName and (TIME between :timeBegin and :timeEnd)";
                    cmd.Parameters.Add(":lineName", OracleType.VarChar);
                    cmd.Parameters[":lineName"].Value = lname;
                    cmd.Parameters.Add(":towerName", OracleType.VarChar);
                    cmd.Parameters[":towerName"].Value = tname;
                    cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                    cmd.Parameters[":timeBegin"].Value = begin;
                    cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                    cmd.Parameters[":timeEnd"].Value = end;
                    OracleDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5) && !dr.IsDBNull(6) && !dr.IsDBNull(7))
                                metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetString(2), dr.GetDateTime(3), dr.GetFloat(4), dr.GetInt64(5), dr.GetFloat(6), dr.GetInt64(7) });
                        }
                    }
                }
            }
            else if (ename.Equals("杆塔倾斜装置"))
            {
                metricHistoryDataTable.Columns.Add("线路名称");  //0
                metricHistoryDataTable.Columns.Add("杆塔名称");  //1
                metricHistoryDataTable.Columns.Add("装置名称");  //2
                metricHistoryDataTable.Columns.Add("采样时间");  //3
                metricHistoryDataTable.Columns.Add("顺线倾斜角1");//4
                metricHistoryDataTable.Columns.Add("顺线倾斜角1_ABNORMAL");
                metricHistoryDataTable.Columns.Add("顺线倾斜角2");
                metricHistoryDataTable.Columns.Add("顺线倾斜角2_ABNORMAL");
                metricHistoryDataTable.Columns.Add("横向倾斜角1");
                metricHistoryDataTable.Columns.Add("横向倾斜角1_ABNORMAL");
                metricHistoryDataTable.Columns.Add("横向倾斜角2");
                metricHistoryDataTable.Columns.Add("横向倾斜角2_ABNORMAL");
                for (int i = 0; i < tableNameList.Count; i++)
                {
                    cmd.CommandText = @"Select TRANSMISSIONLINE, EQUIPMENT, FACILITY,TIME,XANGLE1,XANGLE1_ABNORMAL,XANGLE2,XANGLE2_ABNORMAL,YANGLE1,YANGLE1_ABNORMAL,YANGLE2,YANGLE2_ABNORMAL  from " +
                                        tableNameList[i] + " where TRANSMISSIONLINE = :lineName and EQUIPMENT=:towerName and (TIME between :timeBegin and :timeEnd)";
                    cmd.Parameters.Add(":lineName", OracleType.VarChar);
                    cmd.Parameters[":lineName"].Value = lname;
                    cmd.Parameters.Add(":towerName", OracleType.VarChar);
                    cmd.Parameters[":towerName"].Value = tname;
                    cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                    cmd.Parameters[":timeBegin"].Value = begin;
                    cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                    cmd.Parameters[":timeEnd"].Value = end;

                    OracleDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5) && !dr.IsDBNull(6) && !dr.IsDBNull(7) && !dr.IsDBNull(8) && !dr.IsDBNull(9) && !dr.IsDBNull(10) && !dr.IsDBNull(11))
                                metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetString(2), dr.GetDateTime(3), dr.GetFloat(4), dr.GetInt64(5), dr.GetFloat(6), dr.GetInt64(7), dr.GetFloat(8), dr.GetInt64(9), dr.GetFloat(10), dr.GetInt64(11) });
                        }
                    }
                }
            }
            else if (ename.Equals("杆塔防盗装置"))
            {
                metricHistoryDataTable.Columns.Add("线路名称");
                metricHistoryDataTable.Columns.Add("杆塔名称");
                metricHistoryDataTable.Columns.Add("装置名称");
                metricHistoryDataTable.Columns.Add("采样时间");
                metricHistoryDataTable.Columns.Add("防盗报警1");
                metricHistoryDataTable.Columns.Add("防盗报警1_ABNORMAL");
                metricHistoryDataTable.Columns.Add("防盗报警2");
                metricHistoryDataTable.Columns.Add("防盗报警2_ABNORMAL");
                for (int i = 0; i < tableNameList.Count; i++)
                {
                    cmd.CommandText = @"Select TRANSMISSIONLINE, EQUIPMENT, FACILITY,TIME,ALARM_IR1,ALARM_IR1_ABNORMAL,ALARM_IR2,ALARM_IR2_ABNORMAL from " +
                                        tableNameList[i] + " where TRANSMISSIONLINE = :lineName and EQUIPMENT=:towerName and (TIME between :timeBegin and :timeEnd)";
                    cmd.Parameters.Add(":lineName", OracleType.VarChar);
                    cmd.Parameters[":lineName"].Value = lname;
                    cmd.Parameters.Add(":towerName", OracleType.VarChar);
                    cmd.Parameters[":towerName"].Value = tname;
                    cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                    cmd.Parameters[":timeBegin"].Value = begin;
                    cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                    cmd.Parameters[":timeEnd"].Value = end;
                    OracleDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5) && !dr.IsDBNull(6) && !dr.IsDBNull(7))
                                metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetString(2), dr.GetDateTime(3), dr.GetFloat(4), dr.GetInt64(5), dr.GetFloat(6), dr.GetInt64(7) });
                        }
                    }
                }
            }
            conn.Close();
        }
        catch (OracleException e)
        {

        }
        return metricHistoryDataTable;
    }

    /* 
    * 数据查询-动态增容-历史数据查询 3.2
    * lname:线路名称
    * tname:杆塔名称
    * begin:开始时间
    * end:结束时间
   */
    public DataTable getDTDataQueryDTZR(String lname, String tname, DateTime begin, DateTime end)
    {
        DataTable metricHistoryDataTable = new DataTable();
        try
        {
            String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
            OracleConnection conn = new OracleConnection(connectionString);
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            conn.Open();
            List<String> tableNameList = getTowerHistoryTableNameList(lname, tname, begin, end);
            metricHistoryDataTable.Columns.Add("线路名称");
            metricHistoryDataTable.Columns.Add("杆塔名称");
            metricHistoryDataTable.Columns.Add("采样时间");
            metricHistoryDataTable.Columns.Add("环境温度");
            metricHistoryDataTable.Columns.Add("环境温度_ABNORMAL");
            metricHistoryDataTable.Columns.Add("导线温度");
            metricHistoryDataTable.Columns.Add("导线温度_ABNORMAL");
            metricHistoryDataTable.Columns.Add("实时电流");
            metricHistoryDataTable.Columns.Add("实时电流_ABNORMAL");
            metricHistoryDataTable.Columns.Add("限额电流");
            metricHistoryDataTable.Columns.Add("限额电流_ABNORMAL");
            metricHistoryDataTable.Columns.Add("热稳限额");
            metricHistoryDataTable.Columns.Add("热稳限额_ABNORMAL");
            metricHistoryDataTable.Columns.Add("功率限额");
            metricHistoryDataTable.Columns.Add("功率限额_ABNORMAL");
            for (int i = 0; i < tableNameList.Count; i++)
            {
                cmd.CommandText = @"Select TRANSMISSIONLINE,EQUIPMENT,TIME,TEMPERATURE,TEMPERATURE_ABNORMAL,TEMPERATUREOF_LINE,TEMPERATUREOF_LINE_ABNORMAL,CURRENT_REALTIME,CURRENT_REALTIME_ABNORMAL,MAX_CURRENT,MAX_CURRENT_ABNORMAL,THREHOLDOF_HEAT,THREHOLDOF_HEAT_ABNORMAL,LIMITOF_POWER,LIMITOF_POWER_ABNORMAL from " +
                                    tableNameList[i] + " where TRANSMISSIONLINE = :lineName and EQUIPMENT=:towerName and (TIME between :timeBegin and :timeEnd)";

                cmd.Parameters.Add(":lineName", OracleType.VarChar);
                cmd.Parameters[":lineName"].Value = lname;
                cmd.Parameters.Add(":towerName", OracleType.VarChar);
                cmd.Parameters[":towerName"].Value = tname;
                cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                cmd.Parameters[":timeBegin"].Value = begin;
                cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                cmd.Parameters[":timeEnd"].Value = end;

                OracleDataReader dr = cmd.ExecuteReader();

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5) && !dr.IsDBNull(6) && !dr.IsDBNull(7) && !dr.IsDBNull(8) && !dr.IsDBNull(9) && !dr.IsDBNull(10) && !dr.IsDBNull(11) && !dr.IsDBNull(12) && !dr.IsDBNull(13) && !dr.IsDBNull(14))
                            metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetDateTime(2), dr.GetFloat(3), dr.GetInt64(4), dr.GetFloat(5), dr.GetInt64(6), dr.GetFloat(7), dr.GetInt64(8), dr.GetFloat(9), dr.GetInt64(10), dr.GetFloat(11), dr.GetInt64(12), dr.GetFloat(13), dr.GetInt64(14) });
                    }
                }
            }
            conn.Close();
        }
        catch (OracleException e)
        {

        }
        return metricHistoryDataTable;
    }

    /* 
    * 数据查询-杆塔倾斜-历史数据查询 3.3
    * lname:线路名称
    * tname:杆塔名称
    * begin:开始时间
    * end:结束时间
   */
    public DataTable getDTDataQueryGTQX(String lname, String tname, DateTime begin, DateTime end)
    {
        DataTable metricHistoryDataTable = new DataTable();
        try
        {
            String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
            OracleConnection conn = new OracleConnection(connectionString);
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            conn.Open();
            List<String> tableNameList = getTowerHistoryTableNameList(lname, tname, begin, end);
            metricHistoryDataTable.Columns.Add("线路名称");
            metricHistoryDataTable.Columns.Add("杆塔名称");
            metricHistoryDataTable.Columns.Add("采样时间");
            metricHistoryDataTable.Columns.Add("顺线倾斜角");
            metricHistoryDataTable.Columns.Add("顺线倾斜角_ABNORMAL");
            metricHistoryDataTable.Columns.Add("横向倾斜角");
            metricHistoryDataTable.Columns.Add("横向倾斜角_ABNORMAL");
            metricHistoryDataTable.Columns.Add("顺线倾斜度");
            metricHistoryDataTable.Columns.Add("顺线倾斜度_ABNORMAL");
            metricHistoryDataTable.Columns.Add("横向倾斜度");
            metricHistoryDataTable.Columns.Add("横向倾斜度_ABNORMAL");
            metricHistoryDataTable.Columns.Add("综合倾斜角");
            metricHistoryDataTable.Columns.Add("综合倾斜角_ABNORMAL");
            for (int i = 0; i < tableNameList.Count; i++)
            {
                cmd.CommandText = @"Select TRANSMISSIONLINE,EQUIPMENT,TIME, XANGLE,XANGLE_ABNORMAL,YANGLE,YANGLE_ABNORMAL,GRADIENT_X,GRADIENT_X_ABNORMAL,GRADIENT_Y,GRADIENT_Y_ABNORMAL,GRADIENT_TOWER,GRADIENT_TOWER_ABNORMAL from " +
                                    tableNameList[i] + " where TRANSMISSIONLINE = :lineName and EQUIPMENT=:towerName and (TIME between :timeBegin and :timeEnd)";
                cmd.Parameters.Add(":lineName", OracleType.VarChar);
                cmd.Parameters[":lineName"].Value = lname;
                cmd.Parameters.Add(":towerName", OracleType.VarChar);
                cmd.Parameters[":towerName"].Value = tname;
                cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                cmd.Parameters[":timeBegin"].Value = begin;
                cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                cmd.Parameters[":timeEnd"].Value = end;

                OracleDataReader dr = cmd.ExecuteReader();

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5) && !dr.IsDBNull(6) && !dr.IsDBNull(7) && !dr.IsDBNull(8) && !dr.IsDBNull(9) && !dr.IsDBNull(10) && !dr.IsDBNull(11) && !dr.IsDBNull(12) )
                            metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetDateTime(2), dr.GetFloat(3), dr.GetInt64(4), dr.GetFloat(5), dr.GetInt64(6), dr.GetFloat(7), dr.GetInt64(8), dr.GetFloat(9), dr.GetInt64(10), dr.GetFloat(11), dr.GetInt64(12) });
                    }
                }
            }
            conn.Close();
        }
        catch (OracleException e)
        {

        }
        return metricHistoryDataTable;
    }

    /* 
    * 数据查询-环境气象-历史数据查询 3.4
    * lname:线路名称
    * tname:杆塔名称
    * begin:开始时间
    * end:结束时间
   */
    public DataTable getDTDataQueryHJQX(String lname, String tname, DateTime begin, DateTime end)
    {
        DataTable metricHistoryDataTable = new DataTable();
        try
        {
            String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
            OracleConnection conn = new OracleConnection(connectionString);
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            conn.Open();
            List<String> tableNameList = getTowerHistoryTableNameList(lname, tname, begin, end);
            metricHistoryDataTable.Columns.Add("线路名称");
            metricHistoryDataTable.Columns.Add("杆塔名称");
            metricHistoryDataTable.Columns.Add("采样时间");
            metricHistoryDataTable.Columns.Add("温度");
            metricHistoryDataTable.Columns.Add("温度_ABNORMAL");
            metricHistoryDataTable.Columns.Add("湿度");
            metricHistoryDataTable.Columns.Add("湿度_ABNORMAL");
            metricHistoryDataTable.Columns.Add("风速");
            metricHistoryDataTable.Columns.Add("风速_ABNORMAL");
            metricHistoryDataTable.Columns.Add("风向");
            metricHistoryDataTable.Columns.Add("风向_ABNORMAL");
            metricHistoryDataTable.Columns.Add("雨量");
            metricHistoryDataTable.Columns.Add("雨量_ABNORMAL");
            metricHistoryDataTable.Columns.Add("气压");
            metricHistoryDataTable.Columns.Add("气压_ABNORMAL");
            metricHistoryDataTable.Columns.Add("日照强度");
            metricHistoryDataTable.Columns.Add("日照强度_ABNORMAL");
            for (int i = 0; i < tableNameList.Count; i++)
            {

                cmd.CommandText = @"Select TRANSMISSIONLINE,EQUIPMENT,TIME,
                                       TEMPERATURE,TEMPERATURE_ABNORMAL,HUMIDITY,HUMIDITY_ABNORMAL,WINDSPEED,WINDSPEED_ABNORMAL,
                                       WINDDIRECTION,WINDDIRECTION_ABNORMAL,ATOME_PRESSURE,ATOME_PRESSURE_ABNORMAL,RAINFALL,RAINFALL_ABNORMAL,
                                       SUNLIGHT,SUNLIGHT_ABNORMAL from "
                                            + tableNameList[i] + " where TRANSMISSIONLINE = :lineName and EQUIPMENT=:towerName and (TIME between :timeBegin and :timeEnd)";
                cmd.Parameters.Add(":lineName", OracleType.VarChar);
                cmd.Parameters[":lineName"].Value = lname;
                cmd.Parameters.Add(":towerName", OracleType.VarChar);
                cmd.Parameters[":towerName"].Value = tname;
                cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                cmd.Parameters[":timeBegin"].Value = begin;
                cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                cmd.Parameters[":timeEnd"].Value = end;

                OracleDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5) && !dr.IsDBNull(6) && !dr.IsDBNull(7) && !dr.IsDBNull(8) && !dr.IsDBNull(9) && !dr.IsDBNull(10) && !dr.IsDBNull(11) && !dr.IsDBNull(12) && !dr.IsDBNull(13) && !dr.IsDBNull(14) && !dr.IsDBNull(15) && !dr.IsDBNull(16) )
                            metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetDateTime(2), dr.GetFloat(3), dr.GetInt64(4), dr.GetFloat(5), dr.GetInt64(6), dr.GetFloat(7), dr.GetInt64(8), dr.GetFloat(9), dr.GetInt64(10), dr.GetFloat(11), dr.GetInt64(12), dr.GetFloat(13), dr.GetInt64(14), dr.GetFloat(15), dr.GetInt64(16) });
                    }
                }
            }
            conn.Close();
        }
        catch (OracleException e)
        {

        }
        return metricHistoryDataTable;
    }

    /* 
    * 数据查询-导线覆冰-历史数据查询 3.5
    * lname:线路名称
    * tname:杆塔名称
    * begin:开始时间
    * end:结束时间
    */
    public DataTable getDTDataQueryDXLB(String lname, String tname, DateTime begin, DateTime end)
    {
        DataTable metricHistoryDataTable = new DataTable();
        try
        {
            String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
            OracleConnection conn = new OracleConnection(connectionString);
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            conn.Open();
            List<String> tableNameList = getTowerHistoryTableNameList(lname, tname, begin, end);
            metricHistoryDataTable.Columns.Add("线路名称");
            metricHistoryDataTable.Columns.Add("杆塔名称");
            metricHistoryDataTable.Columns.Add("采样时间");
            metricHistoryDataTable.Columns.Add("温度");
            metricHistoryDataTable.Columns.Add("温度_ABNORMAL");
            metricHistoryDataTable.Columns.Add("风速");
            metricHistoryDataTable.Columns.Add("风速_ABNORMAL");
            metricHistoryDataTable.Columns.Add("湿度");
            metricHistoryDataTable.Columns.Add("湿度_ABNORMAL");
            metricHistoryDataTable.Columns.Add("导线倾斜角");
            metricHistoryDataTable.Columns.Add("导线倾斜角_ABNORMAL");
            metricHistoryDataTable.Columns.Add("导线拉力");
            metricHistoryDataTable.Columns.Add("导线拉力_ABNORMAL");
            metricHistoryDataTable.Columns.Add("导线弧垂");
            metricHistoryDataTable.Columns.Add("导线弧垂_ABNORMAL");
            metricHistoryDataTable.Columns.Add("导线覆冰厚度");
            metricHistoryDataTable.Columns.Add("导线覆冰厚度_ABNORMAL");
            for (int i = 0; i < tableNameList.Count; i++)
            {
                cmd.CommandText = @"Select TRANSMISSIONLINE,EQUIPMENT,TIME, TEMPERATURE,TEMPERATURE_ABNORMAL, WINDSPEED,WINDSPEED_ABNORMAL,HUMIDITY,HUMIDITY_ABNORMAL,ANGLEOF_LINE1,ANGLEOF_LINE1_ABNORMAL,FORCEOF_LINE,FORCEOF_LINE_ABNORMAL,SAGOF_LINE,SAGOF_LINE_ABNORMAL,THICKNESSOF_ICE,THICKNESSOF_ICE_ABNORMAL from " +
                                    tableNameList[i] + " where TRANSMISSIONLINE = :lineName and EQUIPMENT=:towerName and (TIME between :timeBegin and :timeEnd)";
                cmd.Parameters.Add(":lineName", OracleType.VarChar);
                cmd.Parameters[":lineName"].Value = lname;
                cmd.Parameters.Add(":towerName", OracleType.VarChar);
                cmd.Parameters[":towerName"].Value = tname;
                cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                cmd.Parameters[":timeBegin"].Value = begin;
                cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                cmd.Parameters[":timeEnd"].Value = end;

                OracleDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3) && !dr.IsDBNull(4) && !dr.IsDBNull(5) && !dr.IsDBNull(6) && !dr.IsDBNull(7) && !dr.IsDBNull(8) && !dr.IsDBNull(9) && !dr.IsDBNull(10) && !dr.IsDBNull(11) && !dr.IsDBNull(12) && !dr.IsDBNull(13) && !dr.IsDBNull(14) && !dr.IsDBNull(15) && !dr.IsDBNull(16))
                            metricHistoryDataTable.Rows.Add(new Object[] { dr.GetString(0), dr.GetString(1), dr.GetDateTime(2), dr.GetFloat(3), dr.GetInt64(4), dr.GetFloat(5), dr.GetInt64(6), dr.GetFloat(7), dr.GetInt64(8), dr.GetFloat(9), dr.GetInt64(10), dr.GetFloat(11), dr.GetInt64(12), dr.GetFloat(13), dr.GetInt64(14), dr.GetFloat(15), dr.GetInt64(16) });
                    }
                }
            }
            conn.Close();
        }
        catch (OracleException e)
        {

        }
        return metricHistoryDataTable;
    }

   
    /* 状态检测-检测表-L3台账信息查询
     * lname:待查线路名
     * tname:待查杆塔名
     */
    public Accounting getAccoutingInfoDataTable(String lname,String tname)
    {
        
        Accounting accounting=new Accounting(lname,tname);
        try
        {
            String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
            OracleConnection conn = new OracleConnection(connectionString);
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            cmd.CommandText = "select towertype,descripe,span from pgms_tower_info where transmissionline=:lineName and equipment=:towerName";
            cmd.Parameters.Add(":lineName", OracleType.VarChar);
            cmd.Parameters[":lineName"].Value = lname;
            cmd.Parameters.Add(":towerName", OracleType.VarChar);
            cmd.Parameters[":towerName"].Value = tname;
            conn.Open();
            OracleDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if(!dr.IsDBNull(0))
                    accounting.TowerType = dr.GetString(0);
                if (!dr.IsDBNull(1))
                    accounting.Description = dr.GetString(1);
                if (!dr.IsDBNull(2))
                    accounting.Span = dr.GetFloat(2) + "";
            }
            conn.Close();
        }
        catch (OracleException e)
        {
        }
        return accounting;

    }


    /* 状态检测-检测表-L3实时数据查询
     * lname:线路名称
     * tname:杆塔名称
     */
    public DataTable getMetricsDataTable(String lname, String tname)
    {
        String towerType = getTowerType(lname, tname);
        DataTable metricsDataTable = new DataTable();
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        cmd.CommandText = "Select VALUE from (select VALUE from PGMS_CURRENT_INFO t where t.TRANSMISSIONLINE = :lineName and t.EQUIPMENT=:towerName and t.NAME=:metricsName order by t.TIME desc) where rownum = 1";
        cmd.Parameters.Add(":lineName", OracleType.VarChar);
        cmd.Parameters[":lineName"].Value = lname;
        cmd.Parameters.Add(":towerName", OracleType.VarChar);
        cmd.Parameters[":towerName"].Value = tname;
        cmd.Parameters.Add(":metricsName", OracleType.VarChar);
        conn.Open();
        OracleDataReader dr;
        List<String> rlist = new List<string>();
        if (towerType.Equals("TOWER1"))
        {
            metricsDataTable.Columns.Add("杆塔倾斜度(%)");
            metricsDataTable.Columns.Add("红外报警1");
            metricsDataTable.Columns.Add("红外报警2");
            cmd.Parameters[":metricsName"].Value = "杆塔倾斜度";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");
            }
            else
            {
                rlist.Add("-");
            }

            cmd.Parameters[":metricsName"].Value = "红外报警1";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                {
                    String s = dr.GetFloat(0).ToString("f0");
                    if (s.Equals("1"))
                        rlist.Add("正常");
                    else if (s.Equals("2"))
                        rlist.Add("防偷盗");
                    else if (s.Equals("3"))
                        rlist.Add("设备异常");
                    else
                        rlist.Add("未知告警状态");
                }
                else
                    rlist.Add("-");
            }
            else
            {
                rlist.Add("-");
            }

            cmd.Parameters[":metricsName"].Value = "红外报警2";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                {
                    String s = dr.GetFloat(0).ToString("f0");
                    if (s.Equals("1"))
                        rlist.Add("正常");
                    else if (s.Equals("2"))
                        rlist.Add("防偷盗");
                    else if (s.Equals("3"))
                        rlist.Add("设备异常");
                    else
                        rlist.Add("未知告警状态");
                }
                else
                    rlist.Add("-");
            }
            else
            {
                rlist.Add("-");
            }
            metricsDataTable.Rows.Add(rlist.ToArray());
            rlist.Clear();
        }

        else if (towerType.Equals("TOWER2"))
        {
            
            metricsDataTable.Columns.Add("红外报警1");
            metricsDataTable.Columns.Add("红外报警2");
            

            cmd.Parameters[":metricsName"].Value = "红外报警1";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                {
                    String s = dr.GetFloat(0).ToString("f0");
                    if (s.Equals("1"))
                        rlist.Add("正常");
                    else if (s.Equals("2"))
                        rlist.Add("防偷盗");
                    else if (s.Equals("3"))
                        rlist.Add("设备异常");
                    else
                        rlist.Add("未知告警状态");
                }
                else
                    rlist.Add("-");
            }
            else
            {
                rlist.Add("-");
            }

            cmd.Parameters[":metricsName"].Value = "红外报警2";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                {
                    String s = dr.GetFloat(0).ToString("f0");
                    if (s.Equals("1"))
                        rlist.Add("正常");
                    else if (s.Equals("2"))
                        rlist.Add("防偷盗");
                    else if (s.Equals("3"))
                        rlist.Add("设备异常");
                    else
                        rlist.Add("未知告警状态");
                }
                else
                    rlist.Add("-");
            }
            else
            {
                rlist.Add("-");
            }
            metricsDataTable.Rows.Add(rlist.ToArray());
            rlist.Clear();
        }

        else if (towerType.Equals("TOWER3"))
        {
            metricsDataTable.Columns.Add("杆塔倾斜度(%)");
            
            cmd.Parameters[":metricsName"].Value = "杆塔倾斜度";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");
            }
            else
            {
                rlist.Add("-");
            }

            
            metricsDataTable.Rows.Add(rlist.ToArray());
            rlist.Clear();
        }

        else if (towerType.Equals("TOWER4"))
        {
            metricsDataTable.Columns.Add("杆塔倾斜度(%)");
            metricsDataTable.Columns.Add("最大允许电流(A)");
            metricsDataTable.Columns.Add("导线温度(℃)");
            cmd.Parameters[":metricsName"].Value = "杆塔倾斜度";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");
            }
            else
            {
                rlist.Add("-");
            }

            cmd.Parameters[":metricsName"].Value = "最大允许电流";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");
            }
            else
            {
                rlist.Add("-");
            }

            cmd.Parameters[":metricsName"].Value = "导线温度";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");
                
            }
            else
            {
                rlist.Add("-");
            }
            metricsDataTable.Rows.Add(rlist.ToArray());
            rlist.Clear();
        }

        else if (towerType.Equals("TOWER5"))
        {
            metricsDataTable.Columns.Add("温度(℃)");
            metricsDataTable.Columns.Add("湿度(%)");
            metricsDataTable.Columns.Add("弧垂(m)"); 
            metricsDataTable.Columns.Add("悬点导线拉力(kN)");

            metricsDataTable.Columns.Add("覆冰厚度(mm)");
            metricsDataTable.Columns.Add("最大允许电流(A)");
            metricsDataTable.Columns.Add("导线温度(℃)");
            metricsDataTable.Columns.Add("风速(m/s)");

            metricsDataTable.Columns.Add("气压(kPa)");
            metricsDataTable.Columns.Add("雨量(mm/h)");
            metricsDataTable.Columns.Add("日照(w/m^2)");
            metricsDataTable.Columns.Add("风向(。)");
            
            cmd.Parameters[":metricsName"].Value = "温度";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");
            }
            else
            {
                rlist.Add("-");
            }

            cmd.Parameters[":metricsName"].Value = "湿度";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");
            }
            else
            {
                rlist.Add("-");
            }

            cmd.Parameters[":metricsName"].Value = "导线弧垂";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");

            }
            else
            {
                rlist.Add("-");
            }

            cmd.Parameters[":metricsName"].Value = "悬点导线拉力";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");

            }
            else
            {
                rlist.Add("-");
            }

            cmd.Parameters[":metricsName"].Value = "覆冰厚度";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");

            }
            else
            {
                rlist.Add("-");
            }

            cmd.Parameters[":metricsName"].Value = "最大允许电流";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");

            }
            else
            {
                rlist.Add("-");
            }

            cmd.Parameters[":metricsName"].Value = "导线温度";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");

            }
            else
            {
                rlist.Add("-");
            }

            cmd.Parameters[":metricsName"].Value = "风速";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");

            }
            else
            {
                rlist.Add("-");
            }

            cmd.Parameters[":metricsName"].Value = "气压";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");

            }
            else
            {
                rlist.Add("-");
            }

            cmd.Parameters[":metricsName"].Value = "雨量";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");

            }
            else
            {
                rlist.Add("-");
            }

            cmd.Parameters[":metricsName"].Value = "日照";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");

            }
            else
            {
                rlist.Add("-");
            }

            cmd.Parameters[":metricsName"].Value = "风向";
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                if (!dr.IsDBNull(0))
                    rlist.Add(dr.GetFloat(0) + "");
                else
                    rlist.Add("-");

            }
            else
            {
                rlist.Add("-");
            }

            metricsDataTable.Rows.Add(rlist.ToArray());
            rlist.Clear();
        }

        conn.Close();
        return metricsDataTable;
    }


    

    

    

    public List<String> getcorrespondingTowerNameList_DTZR(String lname)
    {
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        string cmdText = String.Format("select equipment from pgms_tower_info where transmissionline='{0}' and (towersheet='TOWER4' or towersheet='TOWER5') order by equipment", lname);
        cmd.CommandText = cmdText;
        conn.Open();
        OracleDataReader dr = cmd.ExecuteReader();
        List<String> nameList = new List<string>();
        if (dr.HasRows)
        {
            while (dr.Read())
            {
                if(!dr.IsDBNull(0))
                    nameList.Add(dr.GetString(0));
            }
        }
        dr.Close();
        conn.Close();
        return nameList;
    }
    public List<String> getcorrespondingTowerNameList_GTQX(String lname)
    {
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        string cmdText = String.Format("select equipment from pgms_tower_info where transmissionline='{0}' and (towersheet='TOWER1' or towersheet='TOWER3' or towersheet='TOWER4') order by equipment", lname);
        cmd.CommandText = cmdText;
        conn.Open();
        OracleDataReader dr = cmd.ExecuteReader();
        List<String> nameList = new List<string>();
        if (dr.HasRows)
        {
            while (dr.Read())
            {
                if (!dr.IsDBNull(0))
                    nameList.Add(dr.GetString(0));
            }
        }
        dr.Close();
        conn.Close();
        return nameList;
    }
    public List<String> getcorrespondingTowerNameList_HJQX(String lname)
    {
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        string cmdText = String.Format("select equipment from pgms_tower_info where transmissionline='{0}' and towersheet='TOWER5' order by equipment", lname);
        cmd.CommandText = cmdText;
        conn.Open();
        OracleDataReader dr = cmd.ExecuteReader();
        List<String> nameList = new List<string>();
        if (dr.HasRows)
        {
            while (dr.Read())
            {
                if (!dr.IsDBNull(0))
                    nameList.Add(dr.GetString(0));
            }
        }
        dr.Close();
        conn.Close();
        return nameList;
    }

    public List<String> getcorrespondingTowerNameList_DXLB(String lname)
    {
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand();
        cmd.Connection = conn;
        string cmdText = String.Format("select equipment from pgms_tower_info where transmissionline='{0}' and towersheet='TOWER5' order by equipment", lname);
        cmd.CommandText = cmdText;
        conn.Open();
        OracleDataReader dr = cmd.ExecuteReader();
        List<String> nameList = new List<string>();
        if (dr.HasRows)
        {
            while (dr.Read())
            {
                if (!dr.IsDBNull(0))
                    nameList.Add(dr.GetString(0));
            }
        }
        dr.Close();
        conn.Close();
        return nameList;
    }

    public static string getTower(String tname)
    {
        string value = null;
        string queryString = String.Format("select towersheet from pgms_tower_info where equipment='{0}'", tname);
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand(queryString, conn);
        conn.Open();
        if (cmd.ExecuteOracleScalar() != null)
        {
            value = cmd.ExecuteOracleScalar().ToString();
        }
        conn.Close();
        return value;
    }
    public DataSet getSpine(String lname, String tname, DateTime begin, DateTime end, string attribute, string attributeB)
    {
        string towerType = null;
        towerType = TowerDAOs.getTower(tname);
        string cmdText = String.Format("select time,{0},{1} from pgms_{2}_{3} where equipment='{4}' and time between TO_TIMESTAMP('{5}', 'yyyy/mm/dd hh24:mi:ssxff') and TO_TIMESTAMP('{6}', 'yyyy/mm/dd hh24:mi:ssxff')", attribute, attributeB, towerType, begin.Date.ToString("yyyy"), tname, begin, end);
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        conn.Open();
        DataSet ds = new DataSet();
        OracleDataAdapter oda = new OracleDataAdapter(cmdText, conn);
        oda.Fill(ds);
        conn.Close();
        return ds;
    }
    public DataSet getSpine(String lname, String tname, DateTime begin, DateTime end)
    {
        string towerType = null;
        towerType = TowerDAOs.getTower(tname);
        string cmdText = String.Format("select time,gradient_x,gradient_y,gradient_tower from pgms_{0}_{1} where equipment='{2}' and time between TO_TIMESTAMP('{3}', 'yyyy/mm/dd hh24:mi:ssxff') and TO_TIMESTAMP('{4}', 'yyyy/mm/dd hh24:mi:ssxff')", towerType, begin.Date.ToString("yyyy"), towerType, begin, end);
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        conn.Open();
        DataSet ds = new DataSet();
        OracleDataAdapter oda = new OracleDataAdapter(cmdText, conn);
        oda.Fill(ds);
        conn.Close();
        return ds;
    }
    public DataSet getSpine(String lname, String tname, DateTime begin, DateTime end, string attribute, string attributeB, string attributeC, string attributeD)
    {
        string towerType = null;
        towerType = TowerDAOs.getTower(tname);
        string cmdText = String.Format("select time,{0},{1},{2},{3} from pgms_{4}_{5} where equipment='{6}' and time between TO_TIMESTAMP('{7}', 'yyyy/mm/dd hh24:mi:ssxff') and TO_TIMESTAMP('{8}', 'yyyy/mm/dd hh24:mi:ssxff')", attribute, attributeB, attributeC, attributeD, towerType, begin.Date.ToString("yyyy"), tname, begin, end);
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        conn.Open();
        DataSet ds = new DataSet();
        OracleDataAdapter oda = new OracleDataAdapter(cmdText, conn);
        oda.Fill(ds);
        conn.Close();
        return ds;
    }
    public DataSet getSpineB(String tname, String attribute, DateTime begin, DateTime end)
    {
        string cmdText = String.Format("select time,value from pgms_history_{0} where equipment='{1}' and name='{2}' and time between TO_TIMESTAMP('{3}', 'yyyy/mm/dd hh24:mi:ssxff') and TO_TIMESTAMP('{4}', 'yyyy/mm/dd hh24:mi:ssxff')", begin.Date.ToString("yyyyMM"), tname, attribute, begin, end);
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        conn.Open();
        DataSet ds = new DataSet();
        OracleDataAdapter oda = new OracleDataAdapter(cmdText, conn);
        oda.Fill(ds);
        conn.Close();
        return ds;
    }
    public DataSet getSpineC(String tname, String attribute, DateTime begin, DateTime end)
    {
        string cmdText = String.Format("select time,value from pgms_history_{0} where equipment='{1}' and name='{2}' and time between TO_TIMESTAMP('{3}', 'yyyy/mm/dd hh24:mi:ssxff') and TO_TIMESTAMP('{4}', 'yyyy/mm/dd hh24:mi:ssxff')", begin.Date.ToString("yyyyMM"), tname, attribute, begin, end);
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        conn.Open();
        DataSet ds = new DataSet();
        OracleDataAdapter oda = new OracleDataAdapter(cmdText, conn);
        oda.Fill(ds);
        conn.Close();
        return ds;
    }
    public string getNow(string towerName, string attribute)
    {
        string value = null;
        string queryString = String.Format("select value from pgms_current_info where equipment='{0}' and name='{1}'", towerName, attribute);
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand(queryString, conn);
        conn.Open();
        if (cmd.ExecuteOracleScalar() != null)
        {
            value = cmd.ExecuteOracleScalar().ToString();
        }
        conn.Close();
        return value;
    }
    public string getNowTime(string towerName, string attribute)
    {
        string value = null;
        string queryString = String.Format("select time from pgms_current_info where equipment='{0}' and name='{1}'", towerName, attribute);
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand(queryString, conn);
        conn.Open();
        if (cmd.ExecuteOracleScalar() != null)
        {
            value = cmd.ExecuteOracleScalar().ToString();
        }
        conn.Close();
        return value;
    }
    public string getHistoryMax(string towerName, string attribute, DateTime begin, DateTime end)
    {
        string value = null;
        string queryString = String.Format("select max(value) from pgms_history_{0} where equipment='{1}' and name='{2}' and time between TO_TIMESTAMP('{3}', 'yyyy/mm/dd hh24:mi:ssxff') and TO_TIMESTAMP('{4}', 'yyyy/mm/dd hh24:mi:ssxff')", begin.Date.ToString("yyyyMM"), towerName, attribute, begin, end);
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        OracleCommand cmd = new OracleCommand(queryString, conn);
        conn.Open();
        if (cmd.ExecuteOracleScalar() != null)
        {
            value = cmd.ExecuteOracleScalar().ToString();
        }
        conn.Close();
        return value;
    }

    public DataSet getAlarm(String tname, DateTime begin, DateTime end)
    {
        string cmdText = String.Format(@"select a.equipment,a.start_time,a.stop_time,a.act_description from (select equipment,act_time as start_time,lead(act_time) over(order by act_time) as stop_time,act_description from pgms_alarm_history where equipment='{0}' order by act_time) a where ((a.start_time between TO_TIMESTAMP('{1}', 'yyyy/mm/dd hh24:mi:ssxff') and TO_TIMESTAMP('{2}', 'yyyy/mm/dd hh24:mi:ssxff')) or (a.stop_time between TO_TIMESTAMP('{3}', 'yyyy/mm/dd hh24:mi:ssxff') and TO_TIMESTAMP('{4}', 'yyyy/mm/dd hh24:mi:ssxff'))) and (a.act_description='杆塔轻度倾斜' or a.act_description='杆塔中度倾斜' or a.act_description='杆塔重度倾斜')", tname, begin, end, begin, end);
        String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
        OracleConnection conn = new OracleConnection(connectionString);
        conn.Open();
        DataSet ds = new DataSet();
        OracleDataAdapter oda = new OracleDataAdapter(cmdText, conn);
        oda.Fill(ds);
        conn.Close();
        return ds;
    }
    /*
     * 数据统计-得到告警持续时间
     */
    public DataTable getAlarmDuration(String lname,String tname,String alarmType,DateTime begin,DateTime end)
    {
        DataTable metricsDataTable = new DataTable();
        try
        {
            String connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["OracleConnectionString"].ConnectionString;
            OracleConnection conn = new OracleConnection(connectionString);
            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            metricsDataTable.Columns.Add("线路名称");
            metricsDataTable.Columns.Add("杆塔名称");
            metricsDataTable.Columns.Add("告警开始时间");
            metricsDataTable.Columns.Add("告警结束时间");
            metricsDataTable.Columns.Add("告警等级");
            if (alarmType.Equals("杆塔倾斜"))
            {
                cmd.CommandText = "select a.equipment, a.start_time, a.stop_time,a.act_description from (select equipment,act_time as start_time,lead(act_time , 1 , :timeEnd) over(order by act_time) as stop_time,act_description from pgms_alarm_history where equipment=:towerName order by act_time) a where (a.start_time between :timeBegin and :timeEnd) or (a.stop_time between :timeBegin and :timeEnd) and a.act_description='杆塔轻度倾斜' or a.act_description='杆塔中度倾斜' or a.act_description='杆塔重度倾斜'";
                cmd.Parameters.Add(":towerName", OracleType.VarChar);
                cmd.Parameters[":towerName"].Value = tname;
                cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                cmd.Parameters[":timeBegin"].Value = begin;
                cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                cmd.Parameters[":timeEnd"].Value = end;
                conn.Open();
                OracleDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3))
                            metricsDataTable.Rows.Add(new object[] { lname, dr.GetString(0), dr.GetDateTime(1), dr.GetDateTime(2), dr.GetString(3) });
                    }
                }
            }
            else if (alarmType.Equals("温度"))
            {
                cmd.CommandText = "select a.equipment, a.start_time, a.stop_time,a.act_description from (select equipment,act_time as start_time,lead(act_time, 1 , :timeEnd) over(order by act_time) as stop_time,act_description from pgms_alarm_history where equipment=:towerName order by act_time) a where (a.start_time between :timeBegin and :timeEnd) or (a.stop_time between :timeBegin and :timeEnd) and a.act_description='温度黄色告警' or a.act_description='温度橙色告警' or a.act_description='温度红色告警'";
                cmd.Parameters.Add(":towerName", OracleType.VarChar);
                cmd.Parameters[":towerName"].Value = tname;
                cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                cmd.Parameters[":timeBegin"].Value = begin;
                cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                cmd.Parameters[":timeEnd"].Value = end;
                conn.Open();
                OracleDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3))
                            metricsDataTable.Rows.Add(new object[] { lname, dr.GetString(0), dr.GetDateTime(1), dr.GetDateTime(2), dr.GetString(3) });
                    }
                }
            }
            else if (alarmType.Equals("风速"))
            {
                cmd.CommandText = "select a.equipment, a.start_time, a.stop_time,a.act_description from (select equipment,act_time as start_time,lead(act_time, 1 , :timeEnd) over(order by act_time) as stop_time,act_description from pgms_alarm_history where equipment=:towerName order by act_time) a where (a.start_time between :timeBegin and :timeEnd) or (a.stop_time between :timeBegin and :timeEnd) and a.act_description='大风黄色告警' or a.act_description='大风橙色告警' or a.act_description='大风红色告警'";
                cmd.Parameters.Add(":towerName", OracleType.VarChar);
                cmd.Parameters[":towerName"].Value = tname;
                cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                cmd.Parameters[":timeBegin"].Value = begin;
                cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                cmd.Parameters[":timeEnd"].Value = end;
                conn.Open();
                OracleDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3))
                            metricsDataTable.Rows.Add(new object[] { lname, dr.GetString(0), dr.GetDateTime(1), dr.GetDateTime(2), dr.GetString(3) });
                    }
                }
            }
            else if (alarmType.Equals("雨量"))
            {
                cmd.CommandText = "select a.equipment, a.start_time, a.stop_time,a.act_description from (select equipment,act_time as start_time,lead(act_time, 1 , :timeEnd) over(order by act_time) as stop_time,act_description from pgms_alarm_history where equipment=:towerName order by act_time) a where (a.start_time between :timeBegin and :timeEnd) or (a.stop_time between :timeBegin and :timeEnd) and a.act_description='降雨黄色告警' or a.act_description='降雨橙色告警' or a.act_description='降雨红色告警'";
                cmd.Parameters.Add(":towerName", OracleType.VarChar);
                cmd.Parameters[":towerName"].Value = tname;
                cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                cmd.Parameters[":timeBegin"].Value = begin;
                cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                cmd.Parameters[":timeEnd"].Value = end;
                conn.Open();
                OracleDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3))
                            metricsDataTable.Rows.Add(new object[] { lname, dr.GetString(0), dr.GetDateTime(1), dr.GetDateTime(2), dr.GetString(3) });
                    }
                }
            }
            else if (alarmType.Equals("导线覆冰"))
            {
                cmd.CommandText = "select a.equipment, a.start_time, a.stop_time,a.act_description from (select equipment,act_time as start_time,lead(act_time, 1 , :timeEnd) over(order by act_time) as stop_time,act_description from pgms_alarm_history where equipment=:towerName order by act_time) a where (a.start_time between :timeBegin and :timeEnd) or (a.stop_time between :timeBegin and :timeEnd) and a.act_description='覆冰轻度告警' or a.act_description='覆冰中度告警' or a.act_description='覆冰重度告警'";
                cmd.Parameters.Add(":towerName", OracleType.VarChar);
                cmd.Parameters[":towerName"].Value = tname;
                cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                cmd.Parameters[":timeBegin"].Value = begin;
                cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                cmd.Parameters[":timeEnd"].Value = end;
                conn.Open();
                OracleDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3))
                            metricsDataTable.Rows.Add(new object[] { lname, dr.GetString(0), dr.GetDateTime(1), dr.GetDateTime(2), dr.GetString(3) });
                    }
                }
            }
            else if (alarmType.Equals("导线温度"))
            {
                cmd.CommandText = "select a.equipment, a.start_time, a.stop_time,a.act_description from (select equipment,act_time as start_time,lead(act_time, 1 , :timeEnd) over(order by act_time) as stop_time,act_description from pgms_alarm_history where equipment=:towerName order by act_time) a where (a.start_time between :timeBegin and :timeEnd) or (a.stop_time between :timeBegin and :timeEnd) and a.act_description='导线温度黄色告警' or a.act_description='导线温度橙色告警' or a.act_description='导线温度红色告警'";
                cmd.Parameters.Add(":towerName", OracleType.VarChar);
                cmd.Parameters[":towerName"].Value = tname;
                cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                cmd.Parameters[":timeBegin"].Value = begin;
                cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                cmd.Parameters[":timeEnd"].Value = end;
                conn.Open();
                OracleDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3))
                            metricsDataTable.Rows.Add(new object[] { lname, dr.GetString(0), dr.GetDateTime(1), dr.GetDateTime(2), dr.GetString(3) });
                    }
                }
            }
            else if (alarmType.Equals("红外"))
            {
                metricsDataTable.Columns[4].ColumnName = "告警描述";
                cmd.CommandText = "select a.equipment, a.start_time, a.stop_time,a.act_description from (select equipment,act_time as start_time,lead(act_time, 1 , :timeEnd) over(order by act_time) as stop_time,act_description from pgms_alarm_history where equipment=:towerName order by act_time) a where (a.start_time between :timeBegin and :timeEnd) or (a.stop_time between :timeBegin and :timeEnd) and a.act_description='红外设备异常' or a.act_description='注意防盗'";
                cmd.Parameters.Add(":towerName", OracleType.VarChar);
                cmd.Parameters[":towerName"].Value = tname;
                cmd.Parameters.Add(":timeBegin", OracleType.Timestamp);
                cmd.Parameters[":timeBegin"].Value = begin;
                cmd.Parameters.Add(":timeEnd", OracleType.Timestamp);
                cmd.Parameters[":timeEnd"].Value = end;
                conn.Open();
                OracleDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        if (!dr.IsDBNull(0) && !dr.IsDBNull(1) && !dr.IsDBNull(2) && !dr.IsDBNull(3))
                            metricsDataTable.Rows.Add(new object[] { lname, dr.GetString(0), dr.GetDateTime(1), dr.GetDateTime(2), dr.GetString(3) });
                    }
                }

            }
            conn.Close();
        }
        catch (OracleException e) { }
        return metricsDataTable;

    }


}
